package com.example.zhunongzonghe.Tasks;

import com.example.zhunongzonghe.service.ZnCollectPostService;
import com.example.zhunongzonghe.service.ZnPostLikeService;
import org.springframework.scheduling.annotation.Scheduled;
import org.springframework.stereotype.Component;

import javax.annotation.Resource;

/**
 * 定时任务：redis的Hash扫描同步数据库点赞数据
 */
@Component
public class SyncPostLikeTasks {

    @Resource
    private ZnPostLikeService znPostLikeService;
    @Resource
    private ZnCollectPostService znCollectPostService;

//    @Scheduled(cron = "0 0 23 * * ?" )//秒、分、时、日、月、星期
//    public void postLikenTasks(){
//        znPostLikeService.syncPostLiked();
//    }
    @Scheduled(cron = "0 0 23 * * ?" )
//    @Scheduled(fixedRate = 5000)
    public void postCollectTasks(){
        System.out.println("定时任务：redis帖子收藏数据同步MySql数据库");
        znCollectPostService.syncPostCollect();
    }

    @Scheduled(cron = "0 0 22 * * ?")
//    @Scheduled(fixedRate = 5000)
    public void del(){
        znCollectPostService.delRepetition();
        System.out.println("已定时删除znCollect表重复数据！！！");
    }
}
